@import '../styles/theme.less';
@import '../styles/animations.less';

// 现代化深色主题聊天页面样式
.chat-container-modern {
  position: relative;
  display: flex;
  height: 100vh;
  background: linear-gradient(135deg, @dark-bg-primary 0%, @dark-bg-secondary 50%, @dark-bg-tertiary 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  color: @text-primary;
  overflow: hidden;

  // 背景装饰
  &::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 50%, rgba(168, 85, 247, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 50% 100%, rgba(109, 40, 217, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 1;
  }

  // 内容容器
  > * {
    position: relative;
    z-index: 2;
  }

  // 侧边栏
  .chat-sidebar-modern {
    width: 280px;
    background: @glass-bg;
    backdrop-filter: @glass-blur;
    -webkit-backdrop-filter: @glass-blur;
    border-right: 1px solid @glass-border;
    display: flex;
    flex-direction: column;
    transition: all @duration-normal @ease-out;
    
    &.collapsed {
      width: 60px;
      
      .sidebar-header h3 {
        opacity: 0;
      }
      
      .conversation-item {
        .conversation-title {
          opacity: 0;
        }
      }
    }

    .sidebar-header {
      padding: @spacing-lg;
      border-bottom: 1px solid @border-color;
      display: flex;
      align-items: center;
      justify-content: space-between;

      h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        background: @primary-gradient;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        transition: opacity @duration-fast @ease-out;
      }

      .toggle-btn {
        background: transparent;
        border: none;
        color: @text-secondary;
        cursor: pointer;
        padding: @spacing-sm;
        border-radius: @radius-md;
        transition: all @duration-fast @ease-out;

        &:hover {
          background: @dark-bg-hover;
          color: @text-primary;
        }
      }
    }

    .new-chat-btn {
      margin: @spacing-md;
      height: 44px;
      background: @primary-gradient;
      border: none;
      border-radius: @radius-lg;
      font-weight: 600;
      font-size: 15px;
      transition: all @duration-normal @ease-out;
      position: relative;
      overflow: hidden;

      &::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        transition: width @duration-slow, height @duration-slow;
      }

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(124, 58, 237, 0.4);

        &::before {
          width: 300px;
          height: 300px;
        }
      }
    }

    .conversation-list {
      flex: 1;
      overflow-y: auto;
      padding: @spacing-sm;
      
      &::-webkit-scrollbar {
        width: @scrollbar-width;
      }

      &::-webkit-scrollbar-track {
        background: @scrollbar-track;
      }

      &::-webkit-scrollbar-thumb {
        background: @scrollbar-thumb;
        border-radius: @radius-sm;

        &:hover {
          background: @scrollbar-thumb-hover;
        }
      }

      .conversation-item {
        padding: @spacing-md;
        margin-bottom: @spacing-sm;
        border-radius: @radius-lg;
        cursor: pointer;
        transition: all @duration-fast @ease-out;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        overflow: hidden;

        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 0;
          height: 100%;
          width: 3px;
          background: @primary-gradient;
          transform: scaleY(0);
          transition: transform @duration-fast @ease-out;
        }

        &:hover {
          background: @dark-bg-hover;
          transform: translateX(4px);

          .delete-btn {
            opacity: 1;
          }
        }

        &.active {
          background: @dark-bg-active;
          
          &::before {
            transform: scaleY(1);
          }

          .conversation-title {
            color: @primary-light;
          }
        }

        .conversation-title {
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 14px;
          color: @text-secondary;
          transition: all @duration-fast @ease-out;
        }

        .delete-btn {
          opacity: 0;
          transition: all @duration-fast @ease-out;
          color: @text-tertiary;
          background: transparent;
          border: none;
          padding: @spacing-xs;
          border-radius: @radius-sm;

          &:hover {
            color: #ef4444;
            background: rgba(239, 68, 68, 0.1);
          }
        }
      }
    }
  }

  // 主聊天区域
  .chat-main-modern {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;

    .chat-header {
      padding: @spacing-lg @spacing-xl;
      background: @glass-bg;
      backdrop-filter: @glass-blur;
      -webkit-backdrop-filter: @glass-blur;
      border-bottom: 1px solid @glass-border;
      display: flex;
      align-items: center;
      justify-content: space-between;

      h2 {
        margin: 0;
        font-size: 24px;
        font-weight: 700;
        background: @primary-gradient;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .header-actions {
        display: flex;
        gap: @spacing-md;

        .model-selector {
          background: @dark-bg-card;
          border: 1px solid @border-color;
          border-radius: @radius-full;
          padding: @spacing-sm @spacing-md;
          color: @text-secondary;
          font-size: 14px;
          display: flex;
          align-items: center;
          gap: @spacing-sm;
          cursor: pointer;
          transition: all @duration-fast @ease-out;

          &:hover {
            border-color: @primary-light;
            color: @primary-light;
          }

          .model-icon {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: @primary-gradient;
          }
        }
      }
    }

    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: @spacing-xl;
      position: relative;

      &::-webkit-scrollbar {
        width: @scrollbar-width;
      }

      &::-webkit-scrollbar-track {
        background: transparent;
      }

      &::-webkit-scrollbar-thumb {
        background: @scrollbar-thumb;
        border-radius: @radius-sm;

        &:hover {
          background: @scrollbar-thumb-hover;
        }
      }

      .welcome-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        text-align: center;

        .welcome-title {
          margin-bottom: @spacing-xxl;

          .logo-icon {
            width: 80px;
            height: 80px;
            margin: 0 auto @spacing-lg;
            background: @primary-gradient;
            border-radius: @radius-xl;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 40px;
            animation: float 3s @ease-in-out infinite;
            box-shadow: @shadow-glow;
          }

          h1 {
            font-size: 36px;
            font-weight: 700;
            margin: 0 0 @spacing-sm;
            background: @primary-gradient;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
          }

          p {
            font-size: 18px;
            color: @text-secondary;
            margin: 0;
          }
        }

        .example-questions {
          display: grid;
          grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
          gap: @spacing-md;
          max-width: 800px;
          width: 100%;

          .example-card {
            background: @glass-bg;
            backdrop-filter: @glass-blur;
            -webkit-backdrop-filter: @glass-blur;
            border: 1px solid @glass-border;
            border-radius: @radius-xl;
            padding: @spacing-lg;
            cursor: pointer;
            transition: all @duration-normal @ease-out;
            position: relative;
            overflow: hidden;

            &::before {
              content: '';
              position: absolute;
              top: -2px;
              left: -2px;
              right: -2px;
              bottom: -2px;
              background: @primary-gradient;
              border-radius: @radius-xl;
              opacity: 0;
              z-index: -1;
              transition: opacity @duration-normal @ease-out;
            }

            &:hover {
              transform: translateY(-4px);
              border-color: transparent;

              &::before {
                opacity: 1;
              }

              .card-icon {
                transform: scale(1.1);
              }
            }

            .card-icon {
              font-size: 32px;
              margin-bottom: @spacing-sm;
              transition: transform @duration-normal @ease-spring;
            }

            .card-title {
              font-size: 16px;
              font-weight: 600;
              color: @text-primary;
              margin-bottom: @spacing-xs;
            }

            .card-desc {
              font-size: 14px;
              color: @text-secondary;
              line-height: 1.5;
            }
          }
        }
      }

      .message-wrapper {
        display: flex;
        gap: @spacing-md;
        margin-bottom: @spacing-lg;
        animation: slideInUp @duration-normal @ease-out;

        &.user {
          flex-direction: row-reverse;

          .message-content-wrapper {
            background: @primary-gradient;
            color: white;
            border-bottom-right-radius: @radius-sm;

            code {
              background: rgba(255, 255, 255, 0.2);
              color: white;
            }
          }
        }

        &.assistant {
          .message-content-wrapper {
            background: @glass-bg;
            backdrop-filter: @glass-blur;
            -webkit-backdrop-filter: @glass-blur;
            border: 1px solid @glass-border;
            border-bottom-left-radius: @radius-sm;
          }
        }

        .message-avatar {
          flex-shrink: 0;
          width: 36px;
          height: 36px;
          border-radius: @radius-lg;
          overflow: hidden;
          background: @dark-bg-card;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 20px;
          border: 1px solid @border-color;
        }

        .message-content-wrapper {
          max-width: 70%;
          padding: @spacing-md @spacing-lg;
          border-radius: @radius-xl;
          position: relative;
          transition: all @duration-fast @ease-out;

          &:hover {
            .message-actions {
              opacity: 1;
            }
          }

          .message-content {
            line-height: 1.6;
            word-break: break-word;

            // Markdown 样式
            h1, h2, h3, h4, h5, h6 {
              margin-top: @spacing-md;
              margin-bottom: @spacing-sm;
              font-weight: 600;
            }

            p {
              margin: @spacing-sm 0;
            }

            // 代码块样式
            .code-block {
              position: relative;
              margin: @spacing-md 0;

              .code-header {
                display: flex;
                justify-content: space-between;
                align-items: center;
                background: #1a1a2a;
                padding: @spacing-sm @spacing-md;
                border-radius: @radius-md @radius-md 0 0;
                border-bottom: 1px solid @border-color;

                .code-language {
                  font-size: 12px;
                  color: @text-secondary;
                  text-transform: uppercase;
                  font-weight: 600;
                }

                .code-copy {
                  background: transparent;
                  border: none;
                  color: @text-tertiary;
                  cursor: pointer;
                  padding: @spacing-xs;
                  border-radius: @radius-sm;
                  transition: all @duration-fast @ease-out;

                  &:hover {
                    background: @dark-bg-hover;
                    color: @text-primary;
                  }
                }
              }

              pre {
                background: @code-bg;
                border-radius: 0 0 @radius-md @radius-md;
                padding: @spacing-md;
                overflow-x: auto;
                margin: 0;

                code {
                  background: transparent;
                  color: @code-text;
                  padding: 0;
                  font-size: 14px;
                  line-height: 1.5;
                }

                &::-webkit-scrollbar {
                  height: 6px;
                }

                &::-webkit-scrollbar-thumb {
                  background: @scrollbar-thumb;
                  border-radius: @radius-sm;
                }
              }
            }

            pre {
              background: @code-bg;
              border-radius: @radius-md;
              padding: @spacing-md;
              overflow-x: auto;
              margin: @spacing-md 0;
              position: relative;

              code {
                background: transparent;
                color: @code-text;
                padding: 0;
                font-size: 14px;
                line-height: 1.5;
              }

              &::-webkit-scrollbar {
                height: 6px;
              }

              &::-webkit-scrollbar-thumb {
                background: @scrollbar-thumb;
                border-radius: @radius-sm;
              }
            }

            code {
              background: rgba(124, 58, 237, 0.1);
              color: @primary-light;
              padding: 2px 6px;
              border-radius: @radius-sm;
              font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
              font-size: 0.9em;
            }

            ul, ol {
              margin: @spacing-sm 0;
              padding-left: @spacing-lg;
            }

            blockquote {
              border-left: 3px solid @primary-light;
              padding-left: @spacing-md;
              margin: @spacing-md 0;
              color: @text-secondary;
            }

            // 链接样式
            .message-link, a {
              color: @primary-light;
              text-decoration: none;
              transition: all @duration-fast @ease-out;
              position: relative;

              &:hover {
                color: #b978ff;
                text-decoration: underline;
              }

              &::after {
                content: '↗';
                font-size: 0.8em;
                margin-left: 2px;
                opacity: 0.6;
              }
            }

            table {
              border-collapse: collapse;
              width: 100%;
              margin: @spacing-md 0;

              th, td {
                border: 1px solid @border-color;
                padding: @spacing-sm @spacing-md;
                text-align: left;
              }

              th {
                background: @dark-bg-card;
                font-weight: 600;
              }
            }
          }

          .typing-cursor {
            display: inline-block;
            width: 3px;
            height: 20px;
            background: @primary-light;
            margin-left: 2px;
            animation: blink 1s infinite;
            vertical-align: text-bottom;
          }

          .message-actions {
            position: absolute;
            bottom: @spacing-sm;
            right: @spacing-sm;
            display: flex;
            gap: @spacing-xs;
            opacity: 0;
            transition: opacity @duration-fast @ease-out;

            button {
              background: @dark-bg-card;
              border: 1px solid @border-color;
              color: @text-secondary;
              padding: @spacing-xs @spacing-sm;
              border-radius: @radius-sm;
              font-size: 12px;
              cursor: pointer;
              transition: all @duration-fast @ease-out;

              &:hover {
                background: @dark-bg-hover;
                color: @text-primary;
                border-color: @primary-light;
              }
            }
          }
        }
      }

      // 滚动到底部按钮
      .scroll-to-bottom {
        position: absolute;
        bottom: @spacing-lg;
        right: @spacing-lg;
        background: @dark-bg-card;
        border: 1px solid @border-color;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all @duration-fast @ease-out;
        box-shadow: @shadow-md;

        &:hover {
          background: @primary-color;
          border-color: @primary-color;
          transform: translateY(-2px);
          box-shadow: @shadow-lg;
        }
      }
    }

    .chat-input-container {
      padding: @spacing-lg @spacing-xl @spacing-xl;
      background: @glass-bg;
      backdrop-filter: @glass-blur;
      -webkit-backdrop-filter: @glass-blur;
      border-top: 1px solid @glass-border;

      .input-wrapper {
        background: @dark-bg-card;
        border: 1px solid @border-color;
        border-radius: @radius-xl;
        padding: @spacing-md;
        transition: all @duration-fast @ease-out;
        position: relative;

        &.focused {
          border-color: @primary-light;
          box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
        }

        .chat-input {
          background: transparent;
          border: none;
          color: @text-primary;
          font-size: 16px;
          line-height: 1.5;
          resize: none;
          width: 100%;
          max-height: 120px;

          &:focus {
            outline: none;
          }

          &::placeholder {
            color: @text-tertiary;
          }
        }

        .input-actions {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-top: @spacing-sm;

          .input-tools {
            display: flex;
            gap: @spacing-sm;

            button {
              background: transparent;
              border: none;
              color: @text-tertiary;
              padding: @spacing-xs;
              cursor: pointer;
              transition: all @duration-fast @ease-out;
              border-radius: @radius-sm;

              &:hover {
                background: @dark-bg-hover;
                color: @text-primary;
              }
            }
          }

          .send-button {
            background: @primary-gradient;
            border: none;
            color: white;
            padding: @spacing-sm @spacing-lg;
            border-radius: @radius-full;
            font-weight: 600;
            cursor: pointer;
            transition: all @duration-fast @ease-out;
            display: flex;
            align-items: center;
            gap: @spacing-sm;

            &:hover:not(:disabled) {
              transform: translateY(-2px);
              box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
            }

            &:disabled {
              opacity: 0.5;
              cursor: not-allowed;
            }

            &.loading {
              .icon {
                animation: rotate 1s linear infinite;
              }
            }
          }
        }
      }

      .input-hints {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: @spacing-sm;
        font-size: 12px;
        color: @text-tertiary;

        .hint-item {
          display: flex;
          align-items: center;
          gap: @spacing-xs;

          kbd {
            background: @dark-bg-card;
            border: 1px solid @border-color;
            padding: 2px 6px;
            border-radius: @radius-sm;
            font-family: monospace;
            font-size: 11px;
          }
        }
      }
    }
  }

  // 响应式
  @media (max-width: 768px) {
    .chat-sidebar-modern {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      z-index: 10;
      transform: translateX(-100%);
      transition: transform @duration-normal @ease-out;

      &.mobile-open {
        transform: translateX(0);
      }
    }

    .chat-main-modern {
      .chat-messages {
        .message-wrapper {
          .message-content-wrapper {
            max-width: 85%;
          }
        }

        .welcome-container {
          .example-questions {
            grid-template-columns: 1fr;
            padding: 0 @spacing-md;
          }
        }
      }
    }
  }
}
